﻿using MvcWechat.Services;
using System.Web.Mvc;
using MvcWechat.Common;

namespace MvcWechat.Controllers
{
    public class WxController : Controller
    { 
       
        // GET: /Wx/
        //[WeixinOAuthAuthorizeAttribute]
        public ActionResult AddressIncrease()
        {
            return CheckView();
        }
        private ActionResult CheckView()
        {
            {
                string key = CommonPage.getKey();
                //供应商的KEY 包含下划线就标识二级 一级的KEY 不能有下划线
                if (key.Contains("_"))
                    ViewBag.IsHideSupplier = "2";
                else
                    ViewBag.IsHideSupplier = "1";
            }
            string viewName = RouteData.Values["action"].ToString();
            Logger.Debug(this.GetType(), "path 1:" + viewName + ",Url.PathAndQuery:" + HttpContext.Request.Url.PathAndQuery);

            string openid = Util.GetOpenIdByCode();
            Logger.Debug(this.GetType(), "path 2 openid:" + openid);
            if (openid != "user" && openid != "code")
            {
                ViewBag.CustomerID = new ServiceController().GetCustomerIdByOpenid(openid).ToString();
                Logger.Debug(this.GetType(), "Info CustomerID 3:" + ViewBag.CustomerID + ",viewName:" + viewName);
                return View(viewName);
            }
            else
            {
                ConfigSettings config = CommonPage.GetConfigSettings();
                string redirectUrl = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}/wx/info&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", config.AppIDByWX, config.Domain);
                ViewBag.CustomerID = "";
                Logger.Debug(this.GetType(), "Info4 viewName:" + viewName + ", redirectUrl :" + redirectUrl);
                return Redirect(redirectUrl);
            }
        }
        public ActionResult AddressChoose()
        {
            return CheckView();
        }
        public ActionResult AddressEdit()
        {
            return CheckView();
        }
        public ActionResult DiaCart()
        {
            return CheckView();
        }
        public ActionResult DiaOrder()
        {
            return CheckView();
        }
        public ActionResult DiasFilter()
        {
            return CheckView();
        }
        public ActionResult Emerald()
        {
            return CheckView();
        }
        public ActionResult EmeraldFilter()
        {
            return CheckView();
        }
        public ActionResult Info()
        {
            return CheckView();
        }
        public ActionResult OrderConfirm()
        {
            return CheckView();
        }
        public ActionResult PayPage()
        {
            return CheckView();
        }
        public ActionResult Ring()
        {
            return CheckView();
        }
        public ActionResult Gold()
        {
            return CheckView();
        }
        public ActionResult GoldFilter()
        {
            return CheckView();
        }
        public ActionResult Cart()
        {
            return CheckView();
        }
        public ActionResult RingDetails()
        {
            return CheckView();
        }
        public ActionResult RingFilter()
        {
            return CheckView();
        }
        public ActionResult Order()
        {
            return CheckView();
        }
        public ActionResult WhiteDias()
        {
            return CheckView();
        }
        public ActionResult Set()
        {
            return View();
        }
    }
}
